<template>

	<view>
		<view class="main">
			<view class="shuru">
				<text class="shuru_tit t22">旧密码</text>
				<input type="text" value="" placeholder="请输入旧密码" class="shuru_text t22" v-model="oldpwd"
					password="true" />
			</view>
			<view class="shuru">
				<text class="shuru_tit t22">新密码</text>
				<input type="text" value="" placeholder="请输入新密码" class="shuru_text t22" v-model="pwd" password="true" />
			</view>
			<view class="shuru">
				<text class="shuru_tit t22">确认密码</text>
				<input type="text" value="" placeholder="请输入确认密码" class="shuru_text t22" v-model="pwds"
					password="true" />
			</view>
		</view>
		<view class="tuic t2" @click="mima()">确认</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				oldpwd: '',
				pwd: '',
				pwds: '',
				mainid: '',
				plat: 1,
				checks: true,
				tel:'',
			}
		},
		onLoad() {
			var _this = this;
			uni.getStorage({
				key: 'user',
				success: function(res) {
					_this.mainid = res.data.id;
				}
			});
			uni.getStorage({
				key: 'plat',
				success: function(res) {
					_this.plat = res.data.plat;
					// console.log(_this.tel);
				}
			});
			uni.getStorage({
				key: 'pass',
				success: function(res) {
					_this.tel = res.data.tel;
				}
			});
		},
		methods: {

			mima() {
				if (this.checks === false) {
					return false
				}
				if (!(this.oldpwd)) {

					uni.showToast({
						title: '请输入旧密码',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				if (!(this.pwd)) {

					uni.showToast({
						title: '请输入新密码',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				if (this.pwds != this.pwd) {

					uni.showToast({
						title: '两次输入密码不一致',
						icon: 'none',
						duration: 2000
					});
					return false
				}


				this.checks = false

				uni.showLoading();
				uni.request({
					header: {
						'content-type': 'application/json', //自定义请求头信息
					},
					url: getApp().globalData.url + 'user/updPassword', //仅为示例，并非真实接口地址。
					method: 'POST',
					data: {
						oldPassword: this.oldpwd, //	旧密码		false	string
						password: this.pwd, //	密码		true	string
						phone: this.tel, //	手机号		true	string
						plat: this.plat, // 平台 true integer
					},
					success: (res) => {
						if (res.data.status == 200) {
							uni.hideLoading();
							this.checks = true;
							uni.showToast({
								title: '密码修改成功,请重新登录',
								icon: 'none',
								duration: 2000
							});
							uni.setStorage({
								key: 'pass',
								data: {
									pass: '',
									tel: '',
									zd: ''
								}
							})
							setTimeout(function() {
								uni.reLaunch({
									url: '/pages/denglu/denglu'
								});
							}, 2000)
						} else {

							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: (error) => {
						uni.hideLoading();
						this.checks = true
						console.log(error)
					}
				});
			},
		}
	}
</script>

<style>
	.shuru {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		border-radius: 1vw;
		overflow: hidden;
		padding: 2vw 4vw;
		background: #fff;
		margin-top: 4vw;
		box-shadow: 0px 0px 5px #eee;
	}

	.shuru_tit {
		width: 30%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: left;
	}

	.shuru_text {
		width: 60%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: right;
		text-align: right;
	}

	.shuru_image {
		width: 10vw;
		height: 10vw;
		display: block;
		float: right;
		border-radius: 2vw;
		overflow: hidden;
		background: #F2F2F2;
	}

	/* .tuic{width: 90%;height: 14vw;display: block;float: left;text-align: center;line-height: 14vw;background: url(../../static/img/tuichu.png) no-repeat top center;background-size:100%; margin: 0 5%;margin-top: 3vw;} */
	.xiugai_yzm {
		width: auto;
		height: 8vw;
		display: block;
		float: right;
		margin-right: 3vw;
		background: #fcbe16;
		padding: 0 3vw;
		line-height: 8vw;
		border-radius: 4vw;
		margin-top: 1.5vw;
	}
</style>
